import bpy
import ctypes
from bpy.types import Panel, Menu

from global_data.global_enum import *
#import engine.sceneOps.engine_sceneOps as scene加减ops
#import engine.sceneOps.renderLayer as scene渲染层




class C_引擎物体管理节点列表_UL_example(bpy.types.UIList):
	def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
		ob = data
		槽 = item
		#print('item.bl_idname = ', item.bl_idname)
		if item.bl_idname == 'idname_engine_场景对象管理节点树':
			layout.prop(item, "name", emboss=False, icon_value=icon)

'''class C_着色器列表_UL_example(bpy.types.UIList):
	def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
		ob = data
		槽 = item
		if item.bl_idname == 'C_ShaderNodeTree':
			layout.prop(item, "name", icon_value=icon)'''
		#print(item.name)
		
class SceneButtonsPanel:
	bl_space_type = 'PROPERTIES'
	bl_region_type = 'WINDOW'
	bl_context = "scene"


class Scene渲染层Panel:
	bl_space_type = 'PROPERTIES'
	bl_region_type = 'WINDOW'
	bl_context = "render_layer"


class C_场景资源管理面板(SceneButtonsPanel, Panel):
	bl_label = 'engine 场景资源管理'
	
	@classmethod
	def poll(cls, context):
		scene = context.scene
		#return True
		return (scene.render.engine in COMPAT_ENGINES)

	def draw(self, context):
		layout = self.layout
		#layout.operator('scene.game_scene_add', text='添加场景', icon='SCENE_DATA')
		layout.label(text='引擎物体管理节点')

		row = layout.row()
		col = row.column()
		col.template_list("C_引擎物体管理节点列表_UL_example", "node_groups", 
														bpy.data, "node_groups", 
														bpy.data.node_groups[0], 
														"active_output", rows=2, type='DEFAULT') 

		#col.template_ID_preview(bpy.data.node_groups.NodeTree, "C_场景节点树")



class C_场景图层操作面板(Scene渲染层Panel, Panel):
	bl_label = '场景渲染层'

	@classmethod
	def poll(cls, context):
		scene = context.scene
		return (scene.render.engine in COMPAT_ENGINES)

	def draw(self, context):
		layout = self.layout

		scene = context.scene
		rd = scene.render

		'''row = layout.row()
		col = row.column()
		col.template_list("RENDERLAYER_UL_renderlayers", "", rd, "layers", rd.layers, "active_index", rows=2)
		
		col = row.column()
		sub = col.column(align=True)
		sub.operator("scene.render_layer_add", icon='ZOOMIN', text="")
		sub.operator("scene.render_layer_remove", icon='ZOOMOUT', text="")
		col.prop(rd, "use_single_layer", icon_only=True)

		顶图层 = rd.layers[scene.active_layer]
		图层大小横向布局 = layout.column()
		图层大小横向布局.prop(顶图层, "prop_单元大小", text='视距', icon='SORTSIZE')
		#for layerID in range(len(rd.layers)):
		#	图层大小横向布局.label('第'+ str(layerID) + '层视距: ' + str(rd.layers[layerID].prop_单元大小))

		引擎场景图层数量 = dllAPI.flexCAPI.f_getScene图层数量(ctypes.c_wchar_p(scene.name))
		ico = 'SORTSIZE'
		if 引擎场景图层数量 < len(rd.layers) :
			ico = 'ERROR'
		图层大小横向布局 = layout.column()
		图层大小横向布局.operator("scene.game_scene_layer_update", icon=ico)'''







classes = (
	C_引擎物体管理节点列表_UL_example,

	C_场景资源管理面板,
	C_场景图层操作面板,
	
)


def register():
	#scene加减ops.register()
	#scene渲染层.register()
	for cls in classes:
		bpy.utils.register_class(cls)

def unregister():
	#scene加减ops.unregister()
	#scene渲染层.unregister()
	for cls in classes:
		bpy.utils.unregister_class(cls)

